package com.hx.net.b;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author jxlgcmh
 * @create 2019-05-10 21:18
 */
public class TCPServer1 {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();
        InputStream in = socket.getInputStream();
        FileOutputStream out = new FileOutputStream("b.txt");
        int len;
        byte[] buf = new byte[1024];
        while ((len = in.read(buf)) != -1) {
            out.write(buf, 0, len);
        }

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("我已经收到了".getBytes());

        in.close();
        out.close();
        outputStream.close();
        socket.close();
        serverSocket.close();
    }
}
